<?php
/**
 * golangshop商城系统 - 团队十年电商经验汇集巨献!
 * =========================================================
 * Copy right 2019-2029 杭州瑞璞玉数字科技有限公司, 保留所有权利。
 * ----------------------------------------------
 * 官方网址: https://www.golangshop.com
 * =========================================================
 */

namespace addon\cashier\shop\controller;

use addon\cashier\model\order\CashierOrderCalculate;
use addon\cashier\model\order\CashierOrderCreate as CashierOrderCreateModel;
use addon\cashier\model\order\CashierOrderPay;
use app\shop\controller\BaseShop;

/**
 * Class User
 * @package app\shop\controller
 */
class Test extends BaseShop
{
    public function test()
    {
        $order_create_model = new CashierOrderCreateModel();
        $data = [
            'site_id' => $this->site_id,//站点id
//            'sku_array' => [["sku_id" => 9399,"num" => 1],["sku_id" => 9400,"num" => 1]],
            'sku_array' => [ [ "money" => 1000, "num" => 1 ] ],
            'member_id' => 555,//购买会员(可有可无)
            'store_id' => 1,
            'mobile' => '',
            'order_from' => 'h5',
            'order_from_name' => 'h5',
            'type' => 'recharge',
            'source' => $this->params[ 'source' ] ?? '',//  is_buy 普通购买  cart  购物车   ‘’  参与活动,
            'cashier_type' => 'cashier',
            'create_time' => time(),
        ];

        $res = $order_create_model->create($data);
        dd($res);
    }


    public function test1()
    {

        $promotion = [ 'reduction' => 20 ];
        $data = array (
            'pay_type' => '',
            'site_id' => $this->site_id,//站点id
            'out_trade_no' => '166391531754635551000',
            'store_id' => 1,
            'promotion' => $promotion,
            'member_id' => 555,
            'cash' => 20
        );
        $cashier_order_calculate_model = new CashierOrderCalculate();
        dd($result = $cashier_order_calculate_model->calculate($data));

    }


    public function test3()
    {
        $promotion = !empty($this->params[ 'promotion' ]) ? json_decode($this->params[ 'promotion' ], true) : [];
        $cashier_order_pay_model = new CashierOrderPay();
        $data = array (
            'pay_type' => 'cash',
            'site_id' => $this->site_id,//站点id
            'out_trade_no' => '166401355934055551000',
            'store_id' => 1,
            'promotion' => $promotion,
            'member_id' => 555,
            'cash' => 20000
        );
        $result = $cashier_order_pay_model->confirm($data);
        dd($result);
    }
}